<?php

namespace IDock\Insurance\AMIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\AMIC\AMICEnums;
use IDock\Insurance\AMIC\Response\AllAMICResponse;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleConfirmResponse extends AllAMICResponse
{

    /**
     * @var VehicleModelPrinter $printer
     */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody()['Body'] ?? [];
        $modelList = $body['vehicleModelList'] ?? [];

        if (!$modelList) {
            return $this;
        }
        $model = $modelList['vehicleModel'] ?? [];

        if (isset($model[0])) {
            foreach ($model as $item) {
                $vehiclePrinter = new VehiclePrinter();
                $vehiclePrinter->item['vehiclePlatId'] = $item['vehiclePlatId'] ?? '';
                $vehiclePrinter->item['actualPrice'] = $item['acturalPrice'] ?? '';
                $vehiclePrinter->item['vehicleStyleUniqueId'] = $item['vehicleStyleUniqueId'] ?? '';
                $vehiclePrinter->item['vehiclePrice'] = $item['vehiclePrice'] ?? '';
                $this->printer->setModelList($vehiclePrinter);
            }
        } else {
            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->item['vehiclePlatId'] = $model['vehiclePlatId'] ?? '';
            $vehiclePrinter->item['actualPrice'] = $model['acturalPrice'] ?? '';
            $vehiclePrinter->item['vehicleStyleUniqueId'] = $model['vehicleStyleUniqueId'] ?? '';
            $vehiclePrinter->item['vehiclePrice'] = $model['vehiclePrice'] ?? '';
            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }


}
